<?php
namespace Admin\Controller;
use Admin\Controller\BaseController;
class ExamquestiontypeController extends BaseController {

    //考题类型列表
    public function index(){
        $count = M('examquestiontype')->count();
        $page = getpage($count,10);
        $examquestiontype_arr = M('examquestiontype')->order('examquestiontype_id desc')->limit($page->firstRow, $page->listRows)->select();
        $this->assign('examquestiontype_arr', $examquestiontype_arr);
        $this->assign('page', $page->show());
        $this->display();
    }

    //添加考题类型
    public function examquestiontype_add(){
        if (I('post.action') == 'examquestiontype_add_action') {
            $this->examquestiontype_add_action();
            exit();
        }
        $this->display();
    }

    //添加考题类型操作
    public function examquestiontype_add_action(){
        if($_POST != array_filter($_POST)){
            $this->error('选项不能有空值');
        }
        if(M('examquestiontype')->data($_POST)->add()){
            $this->redirect('index');
        }else{
            $this->error('添加考题类型失败！');
        }
    }

    //修改考题类型
    public function examquestiontype_edit(){
        if (I('post.action') == 'examquestiontype_edit_action') {
            $this->examquestiontype_edit_action();
            exit();
        }
        $data['examquestiontype_id'] = $_GET['examquestiontype_id'];
        $examquestiontype_arr = M('examquestiontype')->where($data)->find();
        $this->assign('examquestiontype_arr',$examquestiontype_arr);
        $this->display();
    }

    //修改考题类型操作
    public function examquestiontype_edit_action(){
        if($_POST != array_filter($_POST)){
            $this->error('选项不能有空值');
        }
        if(M('examquestiontype')->save($_POST)){
            $this->redirect('index');
        }else{
            $this->error('修改考题类型失败！');
        }
    }


}